package com.probiz.estore.product.dao.impl;

import java.util.List;

import com.probiz.estore.common.model.product.ProductAttGroupItem;
import com.probiz.estore.core.dao.impl.HibernateGenericDaoImpl;
import com.probiz.estore.product.dao.ProductAttGroupItemDao;

/**
 * Dao implementation for ProductAttGroupItem.
*/
public class ProductAttGroupItemDaoImpl extends HibernateGenericDaoImpl<ProductAttGroupItem> implements ProductAttGroupItemDao {

	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.product.dao.ProductAttGroupItemDao#getProductAttGroupItemByProductTypeAndAttribute(java.lang.Integer, java.lang.Integer)
	 */
	public ProductAttGroupItem getProductAttGroupItemByProductTypeAndAttribute(Integer productTypeId, Integer attributeId){
		String hql="from ProductAttGroupItem attItem where attItem.productTypeId=? and attItem.attribute.attributeId=?";
		ProductAttGroupItem productAttGroupItem=(ProductAttGroupItem)findUnique(hql, new Object[]{productTypeId,attributeId});
		return productAttGroupItem;
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.product.dao.ProductAttGroupItemDao#getNumOfQuickSearchAttItemsByProductTypeId(java.lang.Integer)
	 */
	public Long getNumOfQuickSearchAttItemsByProductTypeId(Integer productTypeId){
		return (Long)this.findUnique("select count(ai.productAttGroupItemId) from ProductAttGroupItem ai where ai.isQuickSearch=1 and ai.productTypeId = "+productTypeId);
	}
	

	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.product.dao.ProductAttGroupItemDao#getQuickSearchAttItemsByProductTypeId(java.lang.Integer)
	 */
	public List<ProductAttGroupItem> getQuickSearchAttItemsByProductTypeId(Integer productTypeId){
		return this.findByHql("from ProductAttGroupItem ai where ai.isQuickSearch=1 and ai.productTypeId = ? order by ai.productAttGroup.sortOrder asc,ai.sortOrder asc", productTypeId);
	}

}
